<% layout('/layouts/default.html', {title: '支付账号管理', libs: ['validate','fileupload']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(merchantDetails.isNewRecord ? '新增支付账号' : '编辑支付账号管理')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${merchantDetails}" action="${ctx}/merchant/merchantDetails/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="detailsId"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('支付类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="payType" dictType="payType" maxlength="16" class="form-control required" onchange="payTypeAsync()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('支付名')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="payName" maxlength="16" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('应用id')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="appid" maxlength="32" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('商户id')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="mchId" maxlength="32" class="form-control"/>
							</div>
						</div>
					</div>
				</div>

				<div class="row">

					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('秘钥类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="keyType" dictType="key_type" maxlength="16" class="form-control required" onchange="keyTypeAsync()"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6 hide" id="cert_store_type_div">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('证书存储类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="certStoreType" dictType="cert_store_type" maxlength="16" class="form-control" onchange="certTypeAsync()"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('私钥')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">

								<#form:fileupload id="privateUpload" returnPath="true"
								filePathInputId="keyPrivate" fileNameInputId="upload3Name"
								readonly="false" maxUploadNum="1"/>
								<#form:input path="keyPrivate" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('公钥')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:fileupload id="publicUpload" returnPath="true"
								filePathInputId="keyPublic" fileNameInputId="upload3Name"
								 readonly="false" maxUploadNum="1"/>
								<#form:input path="keyPublic" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('key证书')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="keyCert" maxlength="20480" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('证书密码')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="keyCertPwd" maxlength="32" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('异步回调')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="notifyUrl" maxlength="256" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('同步回调')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="returnUrl" maxlength="256" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('签名方式')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="signType" dictType="sign_type" maxlength="16" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6" id="seller_div">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('收款账号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="seller" maxlength="32" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<#form:hidden path="inputCharset" defaultValue="utf-8" maxlength="16" class="form-control required"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('测试环境')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="isTest" dictType="sys_yes_no" maxlength="16" class="form-control required" />
							</div>
						</div>
					</div>
				</div>

			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('merchant:merchantDetails:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
//
function payTypeAsync(){
    var payType = $('#payType').val();
    console.log(payType);
    switch (payType){
		case "aliPay":
			$('#seller_div').show();//支付宝需要填写收款账号
		    break;
		default:
            $('#seller_div').hide();
            break;
	}
}

function keyTypeAsync(){
    var keyType = $('#keyType').val();
    switch (payType){
        case "cert":
            $('#cert_store_type_div').show();//支付宝需要填写收款账号
            break;
        default:
            $('#cert_store_type_div').hide();
            break;
    }
}

function certTypeAsync(){
    var certType = $('#certType').val();
	switch(certType){
		case 'file':
		    $('#privateUpload_wup').show();
            $('#publicUpload_wup').show();
		    break;
		default:
            $('#privateUpload_wup').hide();
            $('#publicUpload_wup').hide();
            break;
	}
}

$(function(){
    payTypeAsync();
    keyTypeAsync();
    certTypeAsync();
})

</script>